package com.seisys.util;

import java.util.Map;

import org.codehaus.jackson.map.util.JSONPObject;

public class AppUtil {

	protected static Logger logger = Logger.getLogger(AppUtil.class);

	/**
	 * 设置分页的参数
	 * 
	 * @param pd
	 * @return
	 */
	public static PageData setPageParam(PageData pd) {
		String page_now_str = pd.get("page_now").toString();
		int pageNowInt = Integer.parseInt(page_now_str) - 1;
		String page_size_str = pd.get("page_size").toString(); // 每页显示记录数
		int pageSizeInt = Integer.parseInt(page_size_str);

		String page_now = pageNowInt + "";
		String page_start = (pageNowInt * pageSizeInt) + "";

		pd.put("page_now", page_now);
		pd.put("page_start", page_start);

		return pd;
	}

	public static Object returnObject(PageData pd, Map map) {
		if (pd.containsKey("callback")) {
			String callback = pd.get("callback").toString();
			return new JSONPObject(callback, map);
		} else {
			return map;
		}
	}
}
